""""""
import json
import os

import yaml

"""
    读取文件
"""
import configparser

def getProjectRoot():
    # 获取当前文件名
    current_file_path = os.path.realpath(__file__)
    # 获取当前文件名的目录
    current_dir_path = os.path.dirname(current_file_path)

    # 获取当前目录的上级目录
    current_Project_path = os.path.dirname(current_dir_path)

    return current_Project_path

def read_config(option,section="env"):
    # print("读取test>ini文件")
    ini_file_path = getProjectRoot() + r"\test.ini"
    config = configparser.ConfigParser()
    config.read(ini_file_path)
    return config.get(section,option)

def read_yaml(file_name):
    # 拼接yaml文件的全路径
    file_path = getProjectRoot() + "\\test_data\\" + file_name
    # 读取yaml数据文件的内容
    with open(file_path,mode="r",encoding="utf-8") as f:
        c = f.read()
    # 文件内容按照yaml格式加载到python中
    return yaml.load(c,Loader=yaml.FullLoader)

if __name__ == '__main__':
    print(getProjectRoot())
    print(read_config("base_url"))
    print(read_config("db_info"))
    # 将json转换为字典
    db_info = json.loads(read_config("db_info"))
    print(db_info["host"])
    y = read_yaml("register_data.yaml")
    print(y)
    for y1 in y:
        print(y1["data"])